<!-- 采购-销售-库存-公共模板 -->
<template>
	<view>
		<div>
			<navitop>
				<i class="iconfont icon-jiantou-copy" slot="left-slot" @click="outlot"></i>
				<span slot="center-slot">
					<h4>{{titles}}</h4>
				</span>
				<i slot="right-slot">
					<!-- <i class="iconfont icon-sousuo1" style="font-size: 25px;padding-left: 15px;" ></i> -->
					<i class="iconfont icon-youcecaidan" style="font-size: 25px;padding-left: 15px;"
						@click="class_sort"></i>
				</i>
			</navitop>
		</div>
		<view :style="'padding-top:' + nv_height">
			<div class="second_serch">
				<div :class="second_class_list" @click="getList()">
					所有
				</div>
				<div v-for="(item,index) in search_data_list" @click="search_clas(item)"
					:class="second_class_id == item.id ? second_class : ''">
					{{item.programmeName}}
				</div>
			</div>
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption" :style="'padding-top:' + nv_height_lsit + '%'">
				<fontList :rundata="rundataSorce" :titleList="title_list" :deliverType="deliver_type"
					:deliverList="deliver_title_list" :curl_data="Curl_Data" :CurlOption="curl_option"
					v-if="curl_type_one"></fontList>

			</mescroll-body>
		</view>

		<!-- 气泡弹窗 -->
		<chunLei-popups v-model="value" :popData="datas" @tapPopup="bubble" :x="345" :y="95" placement="top-end">
		</chunLei-popups>
	</view>
</template>

<script>
	import navitop from '@/components/common/navi-top'
	import {
		list,
		voucherDynamicPage,
		pageVInventoryCheckMain,
		statisticStorageOnHandVo,
		statisticInOutRecordDetailVo,
		SummaryVo,
		ParentVo
	} from '@/common/api/job/sale.js'
	import {
		Plist,
		voucherPage
	} from '@/common/api/job/bill.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import fontList from "@/pages/common/common/list/fontlist.vue"
	import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups";
	export default {
		components: {
			navitop,
			fontList,
			chunLeiPopups,
		},
		mixins: [MescrollMixin],
		data() {
			return {
				titles: '',
				nv_height: '', //获取导航高度
				nv_height_lsit: '', //获取导航高度
				value: false,
				datas: [{
					title: '添加',
					code: 'billadd',
					icon: 'icon-tubiao_tianjia'
				}],
				// 下拉刷新的配置
				downOption: {
					auto: false,
					beforeEndDelay: 300
				},
				// 上拉加载的配置
				upOption: {
					auto: false,
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						use: true,
						tip: '暂无相关数据'
					},
					textNoMore: '没有更多数据了...',
					toTop: {
						offset: 1000 // 滚动多少才显示to-top 
					}
				},
				title_list: [],
				rundataSorce: [],
				sort_code: '',
				out_code: '',
				pages: 1, // 分页
				sort_key: '',
				c_code: '', // 是否入库

				deliver_type: 0, //  特殊显示

				deliver_title_list: [], // 区分发货单特殊处理

				Curl_Data: '', // 获取url参数

				curl_option: '',

				curl_type: false,

				curl_type_one: false,

				dataSorce: [],

				somvo: '',

				search_data_list: [], //搜索方案列表

				search_type: false,

				second_class: '',

				second_class_id: '',

				second_class_list: 'second_serch_top',

			}
		},
		onLoad(val) {
			this.curl_option = val;
			this.Curl_Data = val;
			this.titles = val.title;
			this.sort_code = val.code;
			this.out_code = val.sort;
			this.typeMenu = val.typeMenu;
			this.sort_key = val.key;
			this.c_code = val.c_code;
			if (val.code == 'SaleDispatchVoucher') {
				this.deliver_type = 1;
			}else if(val.code == 'PurchaseReceiveVoucher' && val.c_code == 1){
				this.deliver_type = 2;
			}
		},
		mounted() {
			this.nv_height = uni.getSystemInfoSync().statusBarHeight + 55 + 'px';
			if (this.curl_option.tak == "1") {
				this.curl_type = true;
				if (this.curl_option.msg == 'Inventory') {
					this.Inventory_list(this.pages);
				} else {
					this.analysis_list(this.pages);
					this.somvo = 1;
				}

			} else {
				this.getList(this.pages);
			}

		},
		methods: {

			search_list() {
				let run_data = [];
				Plist({
					reportCode: this.curl_option.search_code
				}).then(item => {
					if (item.code == 200) {
						this.search_data_list = item.data;
					}
				})
			},

			search_clas(val) {
				uni.showLoading({
					title: '加载中...'
				})
				this.second_class_id = val.id;
				this.second_class = 'second_serch_top';
				this.second_class_list = '';
				let searchData = JSON.parse(val.programmeJson)
				this.deliver_title_list.filter(rst => {
					searchData.filter(tal => {
						if (rst.code == tal.code) {
							this.$set(rst, 'value', tal.value)
						}
					})
				})
				voucherPage({
					designSearchDtos: this.deliver_title_list,
					isMyWarehouse: true,
					isSearchDetail: false,
					page: {
						current: 1,
						size: 10
					},
					someBusinessType: this.curl_option.sort,
					sortOrder: "descend"
				}).then(item => {
					if (item.code == 200) {
						uni.hideLoading();
						this.rundataSorce = item.data.records;
					}
				})
			},

			// 返回
			outlot() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},

			// 气泡弹窗
			class_sort() {
				this.value = !this.value;
			},

			// 弹窗操作
			bubble(val) {
				if (val.code == 'billadd') {

					if (this.Curl_Data.code == 'RRS' ||
						this.Curl_Data.code == 'MaterialDispatchVoucher' ||
						this.Curl_Data.code == 'DelegateRRS' ||
						this.Curl_Data.code == 'DelegateDispatchVoucher'
					) {
						uni.navigateTo({ // 领料处理
							url: '/pages/common/index/purchase/science/science-add?title=' + this.titles +
								'&code=' + this.sort_code + '&sort=' + this.out_code + '&c_code=' + this.c_code +
								'&key=' + this.sort_key + "&search_code=" + this.Curl_Data.search_code +
								'&typeMenu=' + this.typeMenu
						})
					} else {
						uni.navigateTo({
							url: '/components/common/bill/bill-herder-list?title=' + this.titles + '&code=' + this
								.sort_code + '&sort=' + this.out_code + '&c_code=' + this.c_code + '&key=' + this
								.sort_key + "&search_code=" + this.Curl_Data.search_code
						})
					}
				}

			},

			// 获取列表(出入库)
			getList(pages) {
				let getLt = {};
				uni.showLoading({
					title: "加载中..."
				})
				let _this = this;
				this.title_list = [];
				list({
					source: this.sort_code
				}).then((rows) => {
					if (rows.code == 200) {
						this.search_list();
						this.deliver_title_list = rows.data;
						// if(this.pages == 1){
						rows.data.filter((item) => {
							if (item.dataTab == "表头" && item.onFill == true) {
								if (item.code == "voucherDate" || item.code == "inDate") {

								} else {
									_this.title_list.push(item);
								}
							}
						})
						// }
						if(this.Curl_Data.code == 'RRS' ){
							console.log(111)
						}else if(this.Curl_Data.code == 'DelegateRRS' ){
							console.log(222)
						}else {
							for(let i in this.title_list){
								if(this.title_list[i].code == "businessType"){
									this.title_list.splice(i,1);
								}
							} 
						}
					
						if (this.sort_key == "stock") { //处理库存管理
							if (this.sort_code == 'RRS' || this.sort_code == 'DelegateRRS') { // 处理 领料申请 委外领料
								getLt = {
									dataSource: this.sort_code,
									designSearchDtos: rows.data,
									isMyWarehouse: true,
									isSearchDetail: false,
									page: {
										current: pages,
										size: 10
									},
									someBusinessType: this.out_code,
									// startVoucherState: 1,
								};
							} else {
								getLt = {
									designSearchDtos: rows.data,
									isMyWarehouse: true,
									isSearchDetail: false,
									page: {
										current: pages,
										size: 10
									},
									someBusinessType: this.out_code,
								};
							}
						} else {
							getLt = {
								designSearchDtos: rows.data,
								isSearchDetail: false,
								page: {
									current: pages,
									size: 10
								},
								someBusinessType: this.out_code
							};
						}
						voucherDynamicPage(getLt).then((rst) => {
							if (rst.code == 200) {
								if (this.pages !== 1) {
									rst.data.records.filter((item) => {
										this.rundataSorce.push(item);
									})
								} else {
									this.rundataSorce = rst.data.records;
								}
								
								if(this.rundataSorce) {
									this.curl_type_one = true;
								}
								
								uni.hideLoading();
								this.second_class = '';
								this.second_class_list = 'second_serch_top';
							}
						})

					}
				})
			},

			// 获取盘存列表
			Inventory_list(pages) {
				let tL_type = false;
				if (this.curl_option.code == '1') {
					tL_type = true;
				}
				pageVInventoryCheckMain({
					current: pages,
					size: 10,
					isLossOrGain: tL_type
				}).then(item => {
					if (item.code == 200) {
						if (pages == 1) {
							this.dataSorce = item.data.records;
						} else {
							item.data.records.filter(val => {
								this.dataSorce.push(val)
							})
						}
					}
				})
			},


			/*下拉刷新的回调*/
			downCallback(val) {
				// 下拉刷新和上拉加载调同样的接口,直接mescroll.resetUpScroll()即可

				if (this.curl_option.msg == 'Inventory' || this.curl_option.msg == 'analysis') {
					if (this.curl_option.msg == 'Inventory') {
						this.Inventory_list(this.pages);
					} else if (this.curl_option.msg == 'analysis') {
						this.analysis_list(this.pages);
					}
				} else {
					this.getList(this.pages);
				}

				setTimeout(() => {
					this.mescroll.endSuccess();
				}, 500)
			},

			// 上拉加载
			upCallback(page) {
				this.pages++;
				let sun = this.pages;
				if (this.curl_option.msg == 'Inventory' || this.curl_option.msg == 'analysis') {
					if (this.curl_option.msg == 'Inventory') {
						this.Inventory_list(sun);
					} else if (this.curl_option.msg == 'analysis') {
						this.analysis_list(sun);
					}
				} else {
					this.getList(sun);
				}
				// let obj = {
				// 	current: page.num, // 页码, 默认1
				// 	size: page.size, // 页长, 默认10条
				// };
				setTimeout(() => {
					this.mescroll.endErr();
				}, 500)
			},
	
	}
}
</script>

<style scoped lang="scss">
	// 头部切换
	.second_serch {
		height: 90rpx;
		width: 100%;
		line-height: 90rpx;
		background-color: #fff;
		margin-bottom: 10px;
		padding: 0 10px 0 10px;
		display: flex;
		// justify-content: space-between;
		white-space: nowrap;
		overflow-x: scroll;
		overflow-y: hidden;

		div {
			padding: 0 40rpx 0 40rpx;
		}
	}

	//头部切换样式背景
	.second_serch_top {
		background-color: rgb(34, 131, 228);
		color: #fff;
	}
</style>
